#pragma once
#include <vector>
#include <string>
#include <ctemplate/template.h>
//#include "oj_model.hpp"
#include "oj_model2.hpp"

// 将题目返回成网页形式
const std::string template_path = "./template_html/";
class View
{
public:
    void AllExpandHtml(const std::vector<struct Question>& questions, std::string* html)
    {
        // 题目编号 标题 难度
        // 用表格显示
        // 网页路径
        std::string src_html = template_path + "all_questions.html";
        // 形成数据字典
        ctemplate::TemplateDictionary root("all_questions");
        for (const auto& q : questions)
        {
            // 子字典
            ctemplate::TemplateDictionary* sub = root.AddSectionDictionary("question_list");
            sub->SetValue("number", q._num);
            sub->SetValue("title", q._title);
            sub->SetValue("star", q._star);
        }
        // 获取被渲染的html
        ctemplate::Template* tpl = ctemplate::Template::GetTemplate(src_html, ctemplate::DO_NOT_STRIP);
        // 开始渲染
        tpl->Expand(html, &root);
    }

    void OneExpandHtml(const struct Question& q, std::string* html)
    {
        // 题目编号 标题 描述 
        // 网页路径
        std::string src_html = template_path + "one_question.html";
        // 形成数据字典
        ctemplate::TemplateDictionary root("one_question");

        root.SetValue("number", q._num);
        root.SetValue("title", q._title);
        root.SetValue("desc", q._desc);
        root.SetValue("pre_code", q._header);
        // 获取被渲染的html
        ctemplate::Template* tpl = ctemplate::Template::GetTemplate(src_html, ctemplate::DO_NOT_STRIP);
        // 开始渲染
        tpl->Expand(html, &root);
    }
};